<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Test;

class TestController extends Controller
{
    public function test(Request $request)
    {
        $query = Test::query();
        if($request->has('column1')){
            $query->where('column1',$request->column1);
        }
        if($request->has('column2')){
            $query->where('column2',$request->column2);
        }
        if($request->has('column3')){
            $query->where('column3',$request->column3);
        }
        if($request->has('column4')){
            $query->where('column4',$request->column4);
        }
        if($request->has('column5')){
            $query->where('column5',$request->column5);
        }
        if($request->has('column6')){
            $query->where('column6',$request->column6);
        }
        if($request->has('column7')){
            $query->where('column7',$request->column7);
        }
        if($request->has('column8')){
            $query->where('column8',$request->column8);
        }
        if($request->has('column9')){
            $query->where('column9',$request->column9);
        }
        if($request->has('column10')){
            $query->where('column10',$request->column10);
        }
        if($request->has('column11')){
            $query->where('column11',$request->column11);
        }
        if($request->has('column12')){
            $query->where('column12',$request->column12);
        }
        if($request->has('column13')){
            $query->where('column13',$request->column13);
        }
        if($request->has('column14')){
            $query->where('column14',$request->column14);
        }
        if($request->has('column15')){
            $query->where('column15',$request->column15);
        }
        if($request->has('column16')){
            $query->where('column16',$request->column16);
        }
        if($request->has('column17')){
            $query->where('column17',$request->column17);
        }
        if($request->has('column18')){
            $query->where('column18',$request->column18);
        }
        if($request->has('column19')){
            $query->where('column19',$request->column19);
        }
        if($request->has('column20')){
            $query->where('column20',$request->column20);
        }


        if($request->has('order_column1') && $request->order_column1 =='desc'){
            $query->orderBy('column1','desc');
        }elseif($request->has('order_column1') && $request->order_column1 =='asc'){
            $query->orderBy('column1','asc');
        }
        if($request->has('order_column2') && $request->order_column2 =='desc'){
            $query->orderBy('column2','desc');
        }elseif($request->has('order_column2') && $request->order_column2 =='asc'){
            $query->orderBy('column2','asc');
        }
        if($request->has('order_column3') && $request->order_column3 =='desc'){
            $query->orderBy('column3','desc');
        }elseif($request->has('order_column3') && $request->order_column3 =='asc'){
            $query->orderBy('column3','asc');
        }
        if($request->has('order_column4') && $request->order_column4 =='desc'){
            $query->orderBy('column4','desc');
        }elseif($request->has('order_column4') && $request->order_column4 =='asc'){
            $query->orderBy('column4','asc');
        }
        if($request->has('order_column5') && $request->order_column5 =='desc'){
            $query->orderBy('column5','desc');
        }elseif($request->has('order_column5') && $request->order_column5 =='asc'){
            $query->orderBy('column5','asc');
        }
        if($request->has('order_column6') && $request->order_column6 =='desc'){
            $query->orderBy('column6','desc');
        }elseif($request->has('order_column6') && $request->order_column6 =='asc'){
            $query->orderBy('column6','asc');
        }
        if($request->has('order_column7') && $request->order_column7 =='desc'){
            $query->orderBy('column7','desc');
        }elseif($request->has('order_column7') && $request->order_column7 =='asc'){
            $query->orderBy('column7','asc');
        }
        if($request->has('order_column8') && $request->order_column8 =='desc'){
            $query->orderBy('column8','desc');
        }elseif($request->has('order_column8') && $request->order_column8 =='asc'){
            $query->orderBy('column8','asc');
        }
        if($request->has('order_column9') && $request->order_column9 =='desc'){
            $query->orderBy('column9','desc');
        }elseif($request->has('order_column9') && $request->order_column9 =='asc'){
            $query->orderBy('column9','asc');
        }
        if($request->has('order_column10') && $request->order_column10 =='desc'){
            $query->orderBy('column10','desc');
        }elseif($request->has('order_column10') && $request->order_column10 =='asc'){
            $query->orderBy('column10','asc');
        }
        if($request->has('order_column11') && $request->order_column11 =='desc'){
            $query->orderBy('column11','desc');
        }elseif($request->has('order_column11') && $request->order_column11 =='asc'){
            $query->orderBy('column11','asc');
        }
        if($request->has('order_column12') && $request->order_column12 =='desc'){
            $query->orderBy('column12','desc');
        }elseif($request->has('order_column12') && $request->order_column12 =='asc'){
            $query->orderBy('column12','asc');
        }
        if($request->has('order_column13') && $request->order_column13 =='desc'){
            $query->orderBy('column13','desc');
        }elseif($request->has('order_column13') && $request->order_column13 =='asc'){
            $query->orderBy('column13','asc');
        }
        if($request->has('order_column14') && $request->order_column14 =='desc'){
            $query->orderBy('column14','desc');
        }elseif($request->has('order_column14') && $request->order_column14 =='asc'){
            $query->orderBy('column14','asc');
        }
        if($request->has('order_column15') && $request->order_column15 =='desc'){
            $query->orderBy('column15','desc');
        }elseif($request->has('order_column15') && $request->order_column15 =='asc'){
            $query->orderBy('column15','asc');
        }
        if($request->has('order_column16') && $request->order_column16 =='desc'){
            $query->orderBy('column16','desc');
        }elseif($request->has('order_column16') && $request->order_column16 =='asc'){
            $query->orderBy('column16','asc');
        }
        if($request->has('order_column17') && $request->order_column17 =='desc'){
            $query->orderBy('column17','desc');
        }elseif($request->has('order_column17') && $request->order_column17 =='asc'){
            $query->orderBy('column17','asc');
        }
        if($request->has('order_column18') && $request->order_column18 =='desc'){
            $query->orderBy('column18','desc');
        }elseif($request->has('order_column18') && $request->order_column18 =='asc'){
            $query->orderBy('column18','asc');
        }
        if($request->has('order_column19') && $request->order_column19 =='desc'){
            $query->orderBy('column19','desc');
        }elseif($request->has('order_column19') && $request->order_column19 =='asc'){
            $query->orderBy('column19','asc');
        }
        if($request->has('order_column20') && $request->order_column20 =='desc'){
            $query->orderBy('column20','desc');
        }elseif($request->has('order_column20') && $request->order_column20 =='asc'){
            $query->orderBy('column20','asc');
        }
        $per_page = $request->input('per_page',15);
        $data = $query->paginate($per_page);

        return response()->json([
            'code' => 1,'token_expired'=>1,
            'msg' => '获得数据',
            'message'=> '成功获得数据',
            'data'=>$data
            ])->setStatusCode(201);
    }
}
